/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.widget.TextView;

//Class to show the players table of database
public class WatchPlayerDB extends AsyncTask<OpenDB, Integer, String> {

	TextView text;

	public WatchPlayerDB(TextView t) {
		text = t;
	}

	@Override
	protected String doInBackground(OpenDB... params) {
		OpenDB db = params[0];
		SQLiteDatabase watch = db.getReadableDatabase();
		String[] columns = { OpenDB.id, OpenDB.name, OpenDB.position,
				OpenDB.team, OpenDB.rating };
		Cursor cursor = watch.query(OpenDB.table2, columns, null, null, null,
				null, null);
		StringBuffer res = new StringBuffer("Players Database:\n\n");
		cursor.moveToFirst();
		while (!cursor.isAfterLast()) {
			res.append(cursor.getInt(0));
			res.append(',');
			res.append(cursor.getString(1));
			res.append(',');
			res.append(cursor.getString(2));
			res.append(',');
			res.append(cursor.getString(3));
			res.append(',');
			res.append(cursor.getInt(4));
			res.append('\n');
			cursor.moveToNext();
		}
		cursor.close();
		return res.toString();
	}

	@Override
	protected void onPostExecute(String result) {
		text.setText(result.toString());
	}
}